home *** CD-ROM | disk | FTP | other *** search
- /*
- * linux/tools/build.c
- *
- * Copyright (C) 1991, 1992 Linus Torvalds
- */
-
- /*
- * This file builds a disk-image from three different files:
- *
- * - bootsect: exactly 512 bytes of 8086 machine code, loads the rest
- * - setup: 8086 machine code, sets up system parm
- * - system: 80386 code for actual system
- *
- * It does some checking that all files are of the correct type, and
- * just writes the result to stdout, removing headers and padding to
- * the right amount. It also writes some system data to stderr.
- */
-
- /*
- * Changes by tytso to allow root device specification
- * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
- */
-
- #include <stdio.h> /* fprintf */
- #include <string.h>
- #include <stdlib.h> /* contains exit */
- #include <sys/types.h> /* unistd.h needs this */
- #include <sys/stat.h>
- #include <sys/sysmacros.h>
- #include <unistd.h> /* contains read/write */
- #include <fcntl.h>
- #include <linux/a.out.h>
- #include <linux/config.h>
- #include <errno.h>
-
- #define MINIX_HEADER 32
-
- #define N_MAGIC_OFFSET 1024
- #ifndef __BFD__
- static int GCC_HEADER = sizeof(struct exec);
- #endif
-
- #ifdef __BIG_KERNEL__
- #define SYS_SIZE 0xffff
- #else
- #define SYS_SIZE DEF_SYSSIZE
- #endif
-
- #define DEFAULT_MAJOR_ROOT 0
- #define DEFAULT_MINOR_ROOT 0
-
- /* max nr of sectors of setup: don't change unless you also change
- * bootsect etc */
- #define SETUP_SECTS 4
-
- #define STRINGIFY(x) #x
-
- typedef union {
- long l;
- short s[2];
- char b[4];
- } conv;
-
- long intel_long(long l)
- {
- conv t;
-
- t.b[0] = l & 0xff; l >>= 8;
- t.b[1] = l & 0xff; l >>= 8;
- t.b[2] = l & 0xff; l >>= 8;
- t.b[3] = l & 0xff; l >>= 8;
- return t.l;
- }
-
- short intel_short(short l)
- {
- conv t;
-
- t.b[0] = l & 0xff; l >>= 8;
- t.b[1] = l & 0xff; l >>= 8;
- return t.s[0];
- }
-
- void die(const char * str)
- {
- fprintf(stderr,"%s\n",str);
- exit(1);
- }
-
- void usage(void)
- {
- die("Usage: makebootsect as86-image > bootsect");
- }
-
- int main(int argc, char ** argv)
- {
- int i,c,id, sz;
- unsigned long sys_size;
- char buf[1024];
- #ifndef __BFD__
- struct exec *ex = (struct exec *)buf;
- #endif
- char major_root, minor_root;
- struct stat sb;
- unsigned char setup_sectors;
-
- if (argc != 2) usage();
- for (i=0;i<sizeof buf; i++) buf[i]=0;
- if ((id=open(argv[1],O_RDONLY,0))<0)
- die("Unable to open 'boot'");
- if (read(id,buf,MINIX_HEADER) != MINIX_HEADER)
- die("Unable to read header of 'boot'");
- if (((long *) buf)[0]!=intel_long(0x04100301))
- die("Non-Minix header of 'boot'");
- if (((long *) buf)[1]!=intel_long(MINIX_HEADER))
- die("Non-Minix header of 'boot'");
- if (((long *) buf)[3] != 0)
- die("Illegal data segment in 'boot'");
- if (((long *) buf)[4] != 0)
- die("Illegal bss in 'boot'");
- if (((long *) buf)[5] != 0)
- die("Non-Minix header of 'boot'");
- if (((long *) buf)[7] != 0)
- die("Illegal symbol table in 'boot'");
- i=read(id,buf,sizeof buf);
- fprintf(stderr,"Boot sector %d bytes.\n",i);
- if (i != 512)
- die("Boot block must be exactly 512 bytes");
- if ((*(unsigned short *)(buf+510)) != (unsigned short)intel_short(0xAA55))
- die("Boot block hasn't got boot flag (0xAA55)");
- buf[508] = (char) minor_root;
- buf[509] = (char) major_root;
- i=write(1,buf,512);
- return(0);
- }
-